package com.treasure.mall.biz.entity.pay;

import com.treasure.mall.biz.entity.BasePO;
import com.treasure.mall.biz.entity.user.UserPO;
import com.treasure.mall.zbq.common.constant.Constant;
import com.treasure.mall.zbq.common.ienum.order.OrderEnums;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 付款单
 *
 * @author allan
 * @version 1.0.0
 * @date 2020/6/13
 */
@Entity
@Table(name = "zb_payment_bill")
@Setter
@Getter
public class PaymentBillPO extends BasePO {
    @Id
    @Column(name = "id", length = 30)
    private String id;
    @Column(name = "order_id")
    private String orderId;
    @ManyToOne
    @JoinColumn(name = "payer", foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
    private UserPO payer;
    @Column(name = "pay_time", columnDefinition = Constant.DATE_COLUMN_DEFINITION)
    private LocalDateTime payTime;
    /**
     * 是否是第三方支付
     */
    @Column(name = "third_pay")
    private boolean thirdPay;
    /**
     * 支付类型
     */
    @Column(name = "pay_type")
    private OrderEnums.PayType payType;
    /**
     * 支付金额
     */
    @Column(name = "amount", scale = 2, precision = 10)
    private BigDecimal amount;
    /**
     * 用户标识
     */
    @Column(name = "open_id")
    private String openId;
    /**
     * 第三方单号
     */
    @Column(name = "third_trading_no")
    private String thirdTradingNo;
    /**
     * 交易类型
     */
    @Column(name = "deal_type")
    private OrderEnums.DealType dealType;
    @Column(name = "pay_desc")
    private String desc;
    @Column(name = "pay_status")
    private OrderEnums.PayStatus payStatus;
    /**
     * 结果描述
     */
    @Column(name = "result_desc")
    private String resultDesc;
    @Column(name = "auction_session_id")
    private Long auctionSessionId;

    public boolean isSuccess() {
        return payStatus == OrderEnums.PayStatus.PAYED;
    }
}
